$(document).ready(function() {

    $.ajax({
        url: "/index/getMenu",
        type: 'get',
        async: false,
        success: function (data) {
            var data = data.data;
            if (data != null) {

                var z = 0;//用来转化成数字的中介
                // 导航栏Collections的下拉导航
                var collectionNav_li = "";
                //搜索框左边的分类
                var collectionOpt = "";
                for (var d in data) {
                    collectionNav_li += "<li> <a href=\"collection.html?id=" + data[d].id + "\" class=\"site-nav__link\">" + data[d].name + "</a> </li>";
                    collectionOpt += '<option value="' + data[d].id + '">' + data[d].name + '</option>';
                }
                $("#collectionNav").append(collectionNav_li);
                $("#collection-option").append(collectionOpt);

            }

        }

    });



    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
    let newsId = $.getUrlParam('newsId');
    $.ajax({
        url:"http://localhost:8092/agriecomPage/news/details?newsId="+newsId,
        dataType:"json",
        type:"GET",
        success : function(data){
            $(".section-header__left h1").html(data.title);         //title
            //来源和发布时间
            var date = new Date(data.createDate);
            $(".section-header__left p").html("来源： <strong>"+data.source+"</strong>   发布时间： "+date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate());
            //详情内容
            $(".rte").html("");
            $(".rte").html(data.newsDetail);
            //console.log(data);
           // $(".blog-image img").attr("src",data.pic);
            //最新资讯 (3条)
            $.ajax({
                url:"http://localhost:8092/agriecomIndex/newsInfo/latestNews?page=1&limit=3",
                dataType:"json" ,
                type: "GET",
                success:function (data) {

                    $.each(data,function(i,ele){
                        $($(".title")[i]).html("<a href=\"http://localhost:8092/agriecomPage/news/forward?newsId="+ele.id+"\">"+ele.title+"</a>");
                        let date = new Date(ele.createDate);
                        $($(".title")[i]).siblings("time").html(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate());
                    })

                }
            })
        }
        })
})